import Vue from "vue";
import VueRouter from "vue-router";
import { getCookie } from "@/utils/tool";

import dataset from "./modules/dataset";
import dataset_401 from "./modules/401/dataset";
import monitor_401 from "./modules/401/monitor";

// import label from './modules/label'
import notebook from "./modules/notebook";
import algorithmAnalysis from "./modules/algorithmAnalysis";
import notebook_401 from "./modules/401/notebook";
// import modelZnyTestt from "./modules/htzny/modelZnyTestt";
import dag from "./modules/dag";
import dag_cssc_cw from "./modules/dag_cssc_cw";
import task from "./modules/task";
import model from "./modules/model";

import modelEvaluate from "./modules/modelEvaluate";
import modelTestt from "./modules/modelTestt";
// import modelZnyAutoTestt from "./modules/htzny/modelTestt";
import modelConvert from "./modules/modelConvert";
import gameConvert from "./modules/gameConvert";
import modelQuantization from "./modules/modelQuantization";
import gameQuantization from "./modules/gameQuantization";
import modelGameModel from "./modules/modelGameModel";

import model_401 from "./modules/401/model";
import deploy from "./modules/deploy";
import image from "./modules/image";
import inout from "./modules/inout";
// import node from './modules/node'
// import edge from './modules/edge'
import market from "./modules/market";
import myMarket from "./modules/myMarket";
import gameExperimentMarket from "./modules/gameExperimentMarket";
import gameimage from "./modules/gameimage";
import scenario from "./modules/scenario";
import modelEva from "./modules/modelEva";
import modelTest from "./modules/modelTest";
import modelReinforcement from "./modules/modelReinforcement";

// 需要时打开
// import dag_cssc from "./modules/dag_cssc";

// import audit from './modules/audit'

import login from "./modules/login";
import notfount from "@/views/404";
import gameExperiment from "./modules/gameExperiment";
import gameDistributedTraining from "./modules/gameDistributedTraining";
import gameTask from "./modules/gameTask";
import gameModel from "./modules/gameModel";
import gameModelTest from "./modules/gameModelTest";
import algorithm from "./modules/algorithm";
import my_algorithm from "./modules/my_algorithm";
import console from "./modules/console";
import map from "./modules/map";
import ReinforcedDisclosure from "./modules/ReinforcedDisclosure";
import modelGame from "./modules/modelGame";

import develop from "./modules/develop";
import modelDevelop from "./modules/modelDevelop";
import product from "./modules/product";
import gameDeepLearning from "./modules/gameDeepLearning";


Vue.use(VueRouter);

let tempCssc = process.env.VUE_APP_USER == "cssc" && process.env.VUE_APP_VERSIONS == "gamma";
let temp401 = process.env.VUE_APP_USER == "401" && process.env.VUE_APP_VERSIONS == "alpha";
let tempZidonghuasuo = process.env.VUE_APP_USER == "zidonghuasuo" && process.env.VUE_APP_VERSIONS == "alpha";
let temphb = process.env.VUE_APP_USER == "hb" && process.env.VUE_APP_VERSIONS == "alpha";

const routesDeep = [
	{
		path: "/bTree",
		name: "bTree",
		affiliation: "main1",
		meta: { title: "行为树", icon: "icon1", name: "demo" },
		component: () => import("@/views/bTree/index2"),
	},
	{
		path: "/401",
		name: "401",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "401" },
		component: () => import("@/views/401"),
	},
	{
		path: "/401_main",
		name: "401_main",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "401" },
		component: () => import("@/views/401_main"),
	},
	{
		path: "/zidonghuasuo",
		name: "zidonghuasuo",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "zidonghuasuo" },
		component: () => import("@/views/zidonghuasuo"),
	},
	{
		path: "/index-hb",
		name: "index-hb",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "hb" },
		component: () => import("@/views/index-hb"),
	},
	{
		path: "/index-casc",
		name: "index-casc",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "casc" },
		component: () => import("@/views/casc"),
	},
	{
		path: "/monitor",
		name: "monitor",
		affiliation: "main1",
		meta: { title: "工作台", icon: "icon1", name: "401" },
		component: () => import("@/views/index-401"),
	},

	// {
	//   path: '/',
	//   redirect: '/login'
	// },
// 需要时打开

	// ...dag_cssc,
	...modelTest,
	...modelEva,
	...login,
	...market,
	...ReinforcedDisclosure,
	...dataset,
	// ...label,
	...notebook,
	...algorithmAnalysis,
	...dag,
	...model,
	...modelGameModel,
	...task,
	...modelEvaluate,
	...modelReinforcement,
	...modelTestt,
	...modelConvert,
	...modelQuantization,
	...deploy,


	...image,
	...inout,
	...myMarket,
	...gameExperimentMarket,
	...console,
	...modelDevelop,
	...gameimage,
	{
		path: "*",
		name: "notfount",
		component: notfount,
	},
];
const routesReinforce = [
	// {
	//   path: '/', // 需要重新搞
	//   name: 'index',
	//   affiliation: 'main',
	//   meta: { title: '首页', icon: 'icon1', name: 'index' },
	//   component: () => import('@/views/index')
	// },
	{
		path: "/index-casc",
		name: "index-casc",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "casc" },
		component: () => import("@/views/casc"),
	},
	{
		path: "/bTree",
		name: "bTree",
		affiliation: "main1",
		meta: { title: "行为树", icon: "icon1", name: "demo" },
		component: () => import("@/views/bTree/index2"),
	},
	...map,
	...login,
	...algorithm,
	...develop,
	...gameExperiment,
	...gameModel,
	...gameTask,
	// ...modelConvert,
	...gameConvert,
	...gameQuantization,
	...gameDeepLearning,
	...modelGame,
	// ...gameModelTest,  // 模型测试
	// ...modelQuantization,

	...console,
	...image,
	...gameimage,
	...scenario,
	...gameDistributedTraining,
	...my_algorithm,

	...product,
	{
		path: "*",
		name: "notfount",
		component: notfount,
	},
];
const routes401Reinforce = [
	{
		path: "/401rl",
		name: "401rl",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "401" },
		component: () => import("@/views/401rl"),
	},
	...monitor_401,
	...map,
	...login,
	...algorithm,
	...gameExperiment,
	...gameModel,
	...gameTask,
	...gameModelTest,
	...console,
	...image,
	...gameimage,
	...scenario,
	...my_algorithm,
	// ...audit,
	{
		path: "*",
		name: "notfount",
		component: notfount,
	},
];
const routes401force = [
	// {
	//   path: '/', // 需要重新搞
	//   name: 'index',
	//   affiliation: 'main',
	//   meta: { title: '首页', icon: 'icon1', name: 'index' },
	//   component: () => import('@/views/index')
	// },
	{
		path: "/401_main",
		name: "401_main",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "401" },
		component: () => import("@/views/401_main"),
	},
	{
		path: "/401",
		name: "401",
		affiliation: "main1",
		meta: { title: "首页", icon: "icon1", name: "401" },
		component: () => import("@/views/401"),
	},
	{
		path: "/monitor",
		name: "monitor",
		affiliation: "main1",
		meta: { title: "工作台", icon: "icon1", name: "401" },
		component: () => import("@/views/index-401"),
	},
	...monitor_401,
	...modelTest,
	...modelEva,
	...login,
	// ...label,
	...notebook_401,
	...dataset_401,
	...model_401,
	...task,
	...deploy,
	...market,
	...image,
	...myMarket,
	...console,
	// ...audit,
	{
		path: "*",
		name: "notfount",
		component: notfount,
	},
];


let indexPage = [
	{
		path: "/",
		name: "index",
		affiliation: "main",
		meta: { title: "首页", icon: "icon1", name: "index" },
		component: () => import("@/views/index"),
	},
];
if (tempCssc) {
	indexPage = [
		{
			path: "/",
			redirect: "/map",
		},
	];
}
if (temp401) {
	indexPage = [
		{
			path: "/",
			redirect: "/401_main",
		},
	];
}
if (tempZidonghuasuo) {
	indexPage = [
		{
			path: "/",
			redirect: "/zidonghuasuo",
		},
	];
}
if (temphb) {
	indexPage = [
		{
			path: "/",
			redirect: "/index-hb",
		},
	];
}

let routes = [...indexPage, ...routesDeep];
if (process.env.VUE_APP_VERSIONS == "beta" || process.env.VUE_APP_VERSIONS == "gamma") {
	routes = [...indexPage, ...routesReinforce];
}
if (process.env.VUE_APP_USER == "401" && process.env.VUE_APP_VERSIONS == "alpha") {
	routes = [...indexPage, ...routes401force];
}
if (process.env.VUE_APP_USER == "401" && process.env.VUE_APP_VERSIONS == "beta") {
	routes = [...routes401Reinforce];
}
if (process.env.VUE_APP_USER == "htzny" && process.env.VUE_APP_VERSIONS == "delta") {
	routes = [...indexPage, ...routesDeep];
}
if (process.env.VUE_APP_USER == "cssc_cw") {
	routes = [...routes, ...dag_cssc_cw];
}
const router = new VueRouter({
	routes,
});

router.beforeEach((to, from, next) => {
	if (to.path === "/login" && getCookie("login_ticket")) {
		return next(from.path);
	}

	if (to.path !== "/login") {
		let breadCrumb = [];

		if (to.path === "/") {
			sessionStorage.removeItem("menuActive");
		} else {
			const pathArr = to.path.split("/");

			const oneRoute = routes.filter((item) => item.name == pathArr[1]);
			breadCrumb[0] = { content: oneRoute[0]?.meta.title, href: oneRoute[0]?.path };

			if (pathArr[2]) {
				breadCrumb[1] = { content: to.meta.title, href: to.path };
			}
			sessionStorage.setItem("menuActive", JSON.stringify(breadCrumb));
		}
	}

	next();
});

export default router;
